<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="/resource/UserPwoer.tld" prefix="p"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<c:set var="path" value="${pageContext.request.contextPath }" />
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<LINK rel="Bookmark" href="../images/favicon.ico">
<!-- 本框架基本脚本和样式 -->
<script type="text/javascript"
	src="${path }/resource/js/jquery-2.1.4.min.js"></script>
<script type="text/javascript"
	src="${path }/resource/js/systools/MBase.js"></script>


<title></title>
</head>

<div class="ibox-content">
		<form class="form-horizontal" id="dataform"  method="post"
		onsubmit="return verify()" >
	<%-- 	 <input type="hidden" name="tokenUrl" value="${tokenUrl}"> <input
			type="hidden" name="token" value="${token}">

		<c:if test="${obj ne null }">
			<input type="hidden" name="id" value="${obj.id }">
		</c:if>  --%>
		<input class="form-control radius" type="hidden" name="fileSize" id="fileSize" readonly="readonly">
		<input type="hidden" name="projId" id="projId" value="${obj.id}">
		<input type="hidden" name="fileExt" id="fileExt"> 
		<input type="hidden" name="id" value="<c:out value="${projText.id}"/>" >
		<input type="hidden" id="fileName1" value="" >
		<div class="form-group">
			<label class="col-sm-2 control-label">文档名称</label>
			<div class="col-sm-8">
				<input type="text" name="fileName" id="fileName" value="<c:out value="${projText.fileName}"/>"
					class="form-control radius" dataType="*1-50" nullmsg="文件名不能为空">
			</div>
		</div>
		
		<c:if test="${projText ne null}">
			<input type="hidden" id="roleIds" value="${projText.roleIds}">
		</c:if>
		<div class="form-group">
			<label class="col-sm-2 control-label">查看权限</label>
			
			<div class="col-sm-8" id="div1">
			<%-- <select multiple="multiple" class="form-control select2" size="1" name="roleId" id="s1" >
				<c:forEach items="${projPostList}" var="item">
					<option	
						<c:if test="${projText.roleIds eq item.id }"> selected="selected" </c:if>
						value='${item.id }'>${item.postName}</option>
				</c:forEach>
			</select> --%>
			</div>
				
				
			
			<input type="hidden" name="fileUrl" id="fileUrl" value="<c:out value="${projText.fileUrl}"/>">
			<!-- <input type="hidden" name="fileSize" id="fileSize" > -->
			<!-- <input type="hidden" name="roleIds" id="roleIds"> -->
			
		</div>
		<div class="form-group">
		<label class="col-sm-2 control-label">文件上传</label>
			<div class="col-sm-8">
				<input onclick="MTools.chooesFile('#fileText2')" value="<c:out value="${projText.fileUrl}"/>"
					class="input-text upload-url radius form-control" type="text" id="showFileName2"
					readonly style="width: 30%;display: inline;"  onchange="getFile()" onfocus="cleanFileUrl()"> 
					<a onclick="MTools.chooesFile('#fileText2')" class="btn btn-primary radius"> 
					<i   class="fa fa-cloud-upload"></i> 浏览文件 </a> 
					<input type="button" class='btn btn-primary radius'onclick="MTools.upFile('#submitBtn2')" value="上传"> <span id="size" style="color:red;"></span>
			</div>
		</div>
		<div class="form-group">
		<label class="col-sm-2 control-label">&nbsp;</label>
		<h3 style="color: red;">* 注意 ：能被浏览器直接打开的文件请压缩后再上传</h3>
		</div>
		<div class="form-group ">
			<div class="col-sm-12 text-center">
				 <a href="javascript:;" onclick="myForm.submit()"
					class="btn btn-success radius">保存</a>
					<!-- <input type="submit" value="上传" class="btn btn-success radius"> -->
					&nbsp;&nbsp;&nbsp;&nbsp;
				<button onclick="MTools.closeForm()" class="btn btn-danger radius"
					type="button">取消</button>
			</div>
		</div>
	</form>
	<iframe src="" name="blankFrame" id="blankFrame"
				style="height: 100px; width: 100px; display: none;"> </iframe>
	<form class="form form-horizontal" method="post" style="display: none;"
		enctype="multipart/form-data" target="blankFrame"
	action="${path }/resource/plugin/kindeditor/zking_upload_json.jsp?fileType=file&hiddenId=fileUrl">
		<input id="fileText2" type="file"  name="file-1"onchange="MTools.selectFile('#showFileName2','#fileText2','')" 
		 dataType="*1-500" nullmsg="上传文件不能为空"/> 
		 <div class="Validform_checktip"></div>
		<input type="submit" id="submitBtn2"/>
	</form>
</div>
<script type="text/javascript">
	var myForm = MForm.initForm({
		invokeUrl : "${path}/admin/projectText/addOrModify",
		isvalid : true,
		beforeSubmit:function(){
			return verify();
		},
		afterSubmit : function() {
			parent.myGrid.serchData();
		},
	});
	
	
	$(function(){
		var list= new Array();
		if($("#roleIds").val() !=null && $("#roleIds").val() !="" ){
			var roleIds=$("#roleIds").val();
			while(roleIds.length > 0){
				var roleId;
				if(roleIds.indexOf(",") != -1){
					roleId=roleIds.substring(0,roleIds.indexOf(","));
					roleIds=roleIds.substring(roleIds.indexOf(",")+1,roleIds.length)
				}else{
					roleId=roleIds;
					roleIds="";
				}
				list.push(roleId);
			}
		}
		var html="";
		$.AjaxProxy({a : false,c : false}).invoke("${path}/admin/projectText/postNameList",function(loj){
			for(var i = 0; i < loj.getRowCount(); i++){	
				if(list.length >0){
					if(judge(list,loj.getString(i,"id"))){
						html=html+"<input type='checkbox' name='roleIds' value='"+loj.getString(i,"id")+"' ' checked='checked' >"+loj.getString(i,"name") +"&nbsp;&nbsp;&nbsp;&nbsp;"
					}else{
						html=html+"<input type='checkbox' name='roleIds' value='"+loj.getString(i,"id")+"' '> "+loj.getString(i,"name") +"&nbsp;&nbsp;&nbsp;&nbsp;";
					}
				}else{
					html=html+"<input type='checkbox' name='roleIds' value='"+loj.getString(i,"id")+"' '> "+loj.getString(i,"name") +"&nbsp;&nbsp;&nbsp;&nbsp;";
				}
			}
				$("#div1").empty().html(html);
		 })
		 
		/* var fileName= $("#fileName1").val().substring(0,$("#fileName1").val().indexOf("."))
		$("#fileName").val(fileName); */
	})
	//判断值是否在list集合中
	function judge(list,id){
		for(var i=0;i<list.length;i++){
			if(list[i] == id){
				return true;
			}
		}
		return false;
	}
	
	
 	function verify(){
	//	alert($("input[type='checkbox']:checked").length);
		if($("input[type='checkbox']:checked").length==0){
			layer.msg("权限不能为空",{icon:2});
			return false
		}
		if($("#fileName").val() == null || $("#fileName").val() == ""){
			layer.msg("文件名称不能为空",{icon:2});
			return false
		}
			
		if($("#fileUrl").val() == null || $("#fileUrl").val() == ""){
			layer.msg("上传文件为空或格式错误",{icon:2});
			return false
		}
		return true;
	} 
    
	function writeData(_size,_ext){
		var size=_size/1024;
		//文件上传大小
		$("#fileSize").val(size.toFixed(0)+"KB");
		$("#size").html("您上传文件的大小为:"+size.toFixed(0)+"KB");
		//文件名加上后缀名
		$("#fileExt").val(_ext);
	}
</script>
</body>
</html>